﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace Sai_Se_Dung
{
    public partial class Menu : PhoneApplicationPage
    {
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            PlayBackGroundSound();
        }

        public Menu()
        {
            InitializeComponent();
            // Rate apps
            FeedbackOverlay.VisibilityChanged += FeedbackOverlay_VisibilityChanged;
        }

        /// <summary>
        /// Rate apps
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FeedbackOverlay_VisibilityChanged(object sender, EventArgs e)
        {
            //ApplicationBar.IsVisible = (FeedbackOverlay.Visibility != Visibility.Visible);
        }

        private void PlayBackGroundSound()
        {
            if (Option.isOn == true)
            {
                mp3_menu.AutoPlay = true;
                mp3_menu.Play();
            }
            else
            {
                mp3_menu.AutoPlay = false;
                mp3_menu.Stop();
            }
        }

        private void PlayButtonEffectSound()
        {
            if (Option.isOn == true)
            {
                mp3_btn.Play();
            }
        }

        private void btnNewGame_Click(object sender, RoutedEventArgs e)
        {
            PlayButtonEffectSound();
            NavigationService.Navigate(new Uri("/Help.xaml", UriKind.Relative));
        }

        private void btnHelp_Click(object sender, RoutedEventArgs e)
        {
            PlayButtonEffectSound();
            NavigationService.Navigate(new Uri("/Option.xaml", UriKind.Relative));
        }

        private void btnOption_Click(object sender, RoutedEventArgs e)
        {
            PlayButtonEffectSound();
            NavigationService.Navigate(new Uri("/About.xaml", UriKind.Relative));
        }

        private void btnAbout_Click(object sender, RoutedEventArgs e)
        {
            PlayButtonEffectSound();
            NavigationService.Navigate(new Uri("/HighScore.xaml", UriKind.Relative));
        }

        private void btnHighScore_Click(object sender, RoutedEventArgs e)
        {
            PlayButtonEffectSound();
            NavigationService.Navigate(new Uri("/Play.xaml", UriKind.Relative));

            //if (Play.isHome == true)
            //{
            //    switch (Play.m_level)
            //    {
            //        case 1:
            //            if (Play.m_time < 60)
            //            {
            //                new Play().SetCurrentLevel();
            //            }
            //            break;
            //        case 2:
            //            if (Play.m_time < 6)
            //            {
            //                new Play().SetCurrentLevel();
            //            }
            //            break;
            //        case 3:
            //            if (Play.m_time < 75)
            //            {
            //                new Play().SetCurrentLevel();
            //            }
            //            break;
            //    }
            //    Play.isHome = false;
            //}
   
        }

        private void mp3_MediaEnded(object sender, RoutedEventArgs e)
        {
            PlayBackGroundSound();
        }

        /// <summary>
        /// BACK button pressed event handler
        /// </summary>
        /// <param name="e"></param>
        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            if (Option.isOn == true)
            {
                mp3_btn.Play();
            }

            if (NavigationService.CanGoBack)
            {
                while (NavigationService.RemoveBackEntry() != null)
                {
                    NavigationService.RemoveBackEntry();
                }
            }
            NavigationService.Navigate(new Uri("/Confirm.xaml", UriKind.Relative));
        }
    }
}